package com.googlecode.marrowboy.writers;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

/**
 * {@link CssProvider} used when none is specified. Has some CSS hard-coded.
 * 
 * @author mjg
 */
public class DefaultCssProvider implements CssProvider {

	private static final String DEFAULT_CSS = "default.css";
	private final String css;

	/**
	 * Constructor.
	 * 
	 * Uses the default css file packaged with MarrowBoy.
	 */
	public DefaultCssProvider() {
		this(DEFAULT_CSS);
	}

	/**
	 * Constructor.
	 * 
	 * @param cssFile
	 *            the name of the css file to try to find on the classpath.
	 */
	public DefaultCssProvider(String cssFile) {

		InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(cssFile);

		try {
			css = IOUtils.toString(inputStream);

		} catch (IOException e) {
			throw new RuntimeException("Exception cuaght loading css", e);

		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * This implementation returns some hard-coded CSS.
	 */
	public String getCss() {
		return css;
	}

}
